#include "Config.h"
#include "Common/MemStream.h"
#include "MsgHandler/MsgPool.h"
#include "ServerClient.h"
#include "Server.h"

ServerClient::ServerClient()
{

}

ServerClient::~ServerClient()
{

}

bool ServerClient::isConned()
{
	return _session >= 0;
}

UInt32 ServerClient::getRoomCount()
{ 
	return _serverData._roomCount;	
}

UInt32 ServerClient::getOnlineCount()
{ 
	return _serverData._onlineCount;	
}

UInt32 ServerClient::incRoomCount()	
{ 
	return ++ _serverData._roomCount; 
}

UInt32 ServerClient::incOnlineCount()
{ 
	return ++ _serverData._onlineCount;
}

UInt32 ServerClient::decRoomCount()
{
	if ( _serverData._roomCount > 0 )
		-- _serverData._roomCount;
	return _serverData._roomCount;	
}

UInt32 ServerClient::decOnlineCount()
{
	if ( _serverData._onlineCount > 0 )
		-- _serverData._onlineCount;
	return _serverData._onlineCount;
}

void ServerClient::syncServerData( UInt32 roomCount, UInt32 onlineCount )
{
	_serverData._roomCount = roomCount;
	_serverData._onlineCount = onlineCount;
	//printf("Sid = %u, RoomCount = %u, OnlineCount = %u\n", getId(), roomCount, onlineCount);
	//DEBUG_LOG("SyncServerData : SID=[%u] RoomCount=[%u] PlayerCount=[%u]", _serverData._id, _serverData._roomCount, _serverData._onlineCount);
}

void ServerClient::saveServerData()
{
	//MemStream ms;
	//ms << _serverData._id << _serverData._roomCount << _serverData._onlineCount;
	//MsgHdr hdr(ms.size(), 0x430, Thread_DB);
	//MSGPOOL().pushMsg( hdr, ms.body() );
}

void ServerClient::send( Stream& st )
{
	NETWORK()->SendMsgToClient( _session, st );
}

void ServerClient::send(void * data, UInt16 len)
{
	NETWORK()->SendMsgToClient( _session, data, len );
}